from django.db import models


# Create your models here.
# 图书类
class BookInfo(models.Model):
    title = models.CharField(max_length=20)
    pub_date = models.DateTimeField()

    def __str__(self):
        return self.title


# 英雄人物类
class HreoInfo(models.Model):
    name = models.CharField(max_length=20)
    gender = models.BooleanField(default=True)  # True:男  False：女
    content = models.CharField(max_length=100)
    book = models.ForeignKey('BookInfo', on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    def skill(self):
        return self.content

    skill.short_description = '英雄技能'


# 账号类
class Account(models.Model):
    username = models.CharField(max_length=20, null=True, blank=True, verbose_name='用户名')
    password = models.CharField(max_length=50, null=False, blank=True, verbose_name='密码')
    register_date = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name='注册时间')


# 联系人
class Contact(models.Model):
    address = models.CharField(max_length=200, null=True)
    code = models.CharField(max_length=20, null=True)
    mobile = models.CharField(max_length=20, null=True)
    account = models.OneToOneField(Account, on_delete=models.CASCADE)


# 多对多
class Host(models.Model):
    host = models.CharField(max_length=20)
    ip = models.GenericIPAddressField(protocol='ipv4')
    port = models.IntegerField()


class Application(models.Model):
    name = models.CharField(max_length=32)
    h = models.ManyToManyField(to='Host')


class Student(models.Model):
    name = models.CharField(max_length=5)
    sex = models.CharField(max_length=3)
    age = models.CharField(max_length=3)
